package com.trkj.controller.hjj;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.trkj.dao.hjj.ConfirmaffairDAO;
import com.trkj.pojo.Affaircategory;
import com.trkj.pojo.Confirmaffair;
import com.trkj.pojo.Holiday;
import com.trkj.pojo.Leaveconfirm;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.ServiceException;
import com.trkj.service.hjj.Operationservice;
import com.trkj.vo.Result_AddRule_Result;
import com.trkj.vo.Leaveaddvo;
import com.trkj.vo.Optionsvo;

@Controller

public class OperationControllerer {
	@Autowired
	private Operationservice operationservice;
	@Autowired
	private ConfirmaffairDAO confirmaffairDAO;
	
		//确认事务中心主界面
		@GetMapping("data_operation")
		public String operation(){
			return "hjj/operation";
		}
		//显示所有信息(请假确认新增界面)
		@GetMapping("Confirmation_sheet")
		public String sheet(){
			return "hjj/sheet";
		}
		//显示所有信息(补班确认新增界面)
		@GetMapping("Conbuban_sheet")
		public String buban(){
			return "hjj/supplementaryadd";
		}
		//显示所有信息(外勤确认新增界面)to_field_addition
		@GetMapping("to_field_addition")
		public String waiqin(){
			return "hjj/field_addition";
		}
		//显示所有信息(加班确认新增界面)
		@GetMapping("to_field_addjiaban")
		public String jiaban(){
			return "hjj/overtime_add";
		}
		//显示所有信息(调休确认新增界面)
		@GetMapping("to_field_addtiaoxiu")
		public String tiaoxiu(){
			return "hjj/break_up";
		}
		//显示所有信息(补卡确认新增界面)
		@GetMapping("to_field_addcard")
		public String addcard(){
			return "hjj/findaddcard";
		}
		//确认事务中心编辑
		@GetMapping("to_option_leaveupdate")
		public String attendancess(Long conaffId,Model mod){
			Confirmaffair attr =confirmaffairDAO.findOne(conaffId);
			mod.addAttribute("leaves", attr);
			return "hjj/leaveupdate";
		}
		//编辑
		@RequestMapping("shq_update_options")
		@ResponseBody
		public Result_AddRule_Result Affaircategoryupdates(Long  stainId,String stainName,Long holidayId,Long affcaId,Long conaffId,Timestamp conaffEndtdate,Timestamp conaffStartdate,String affcaType,String conaffReason){
			try {
				operationservice.optionsupdate(stainId, stainName, holidayId, affcaId, conaffId, conaffEndtdate, conaffStartdate, affcaType, conaffReason);
				System.out.println(affcaId+" "+affcaType);
				return Result_AddRule_Result.SUCCESS;
			} catch (ServiceException e) {
				e.printStackTrace();
				return Result_AddRule_Result.failure(e.getMessage());
			}
		}
		/**
		 * 
		 * @param page
		 * @param rows
		 * @return
		 */
		//显示所有信息
		@PostMapping("findall_operation")
		@ResponseBody
		public Map findallsd(int page, int rows){
			Page<JSONArray> pages = PageHelper.startPage(page, rows);
			operationservice.selectAll_opton();
			Map map = new HashMap<>();
			map.put("total", pages.getTotal());
			map.put("rows", pages.getResult());
			return map;
				
			}
		/**
		 * 查询所有的事物类型
		 * @return
		 */
		@RequestMapping("find_aff_gory")
		@ResponseBody
		public JSONArray findAllAffaitcategory(){
			return operationservice.findAllAffaitcategory();
		}
		/**
		 * 按照事物类型查询所有的事物中心
		 * @param page
		 * @param rows
		 * @param affcaType
		 * @return
		 */
		@RequestMapping("is_all_confair_maffair_sw")
		@ResponseBody
		public Map findconFAIRMAFFAIR_SW(int page,int rows,String affcaType){
			Page<JSONArray> pages = PageHelper.startPage(page, rows);
			operationservice.findconFAIRMAFFAIR_SW(affcaType);
			Map map = new HashMap<>();
			map.put("total", pages.getTotal());
			map.put("rows", pages.getResult());
			return map;
		}
		/**
		 * 按照员工名字模糊搜索事物中心
		 * @param option
		 * @return
		 */
		@RequestMapping("is_all_findFairmaffair_Mohu")
		@ResponseBody
		public Map findFairmaffair_Mohu(int page,int rows,String stainName){
			Page<JSONArray> pages = PageHelper.startPage(page, rows);
			operationservice.findFairmaffair_Mohu(stainName);
			Map map = new HashMap<>();
			map.put("total", pages.getTotal());
			map.put("rows", pages.getResult());
			return map;
		}
		//请假确认新增
		@RequestMapping("shq_options_adds")
		@ResponseBody
		public Result_AddRule_Result optionadd(Optionsvo option){
			try {
				operationservice.optionadd(option);
				return Result_AddRule_Result.SUCCESS;
			} catch (ServiceException e) {
				e.printStackTrace();
				return Result_AddRule_Result.failure(e.getMessage());
			}
		}
		//补班确认新增
		@RequestMapping("shq_options_bubanadds")
		@ResponseBody
		public Result_AddRule_Result optionbubanadd(Optionsvo option){
			try {
				operationservice.optionbubanadd(option);
				return Result_AddRule_Result.SUCCESS;
			} catch (ServiceException e) {
				e.printStackTrace();
				return Result_AddRule_Result.failure(e.getMessage());
				}
			}
		//外勤确认新增
		@RequestMapping("shq_options_waiqinadds")
		@ResponseBody
		public Result_AddRule_Result optionwaiqinadd(Optionsvo option){
			try {
				operationservice.optionwaiqinadd(option);
				return Result_AddRule_Result.SUCCESS;
			} catch (ServiceException e) {
				e.printStackTrace();
				return Result_AddRule_Result.failure(e.getMessage());
				}
			}
		
		
		
		
		//显示所有q信息(假种名称)
		@PostMapping("find_all_holiday")
		@ResponseBody
		public List<Holiday> findall(){
			return operationservice.selectAll_holidy();
		}
		//显示所有q信息(假种名称)
		@PostMapping("find_all_aff")
		@ResponseBody
		public List<Affaircategory> findalls(){
			return operationservice.selectAll_holidys();
		}
		
		//显示所有q信息(无假种名称)
		@PostMapping("find_all_holidayno")
		@ResponseBody
		public List<Holiday> findallno(){
			return operationservice.selectAll_holidyno();
		}
		//显示所有q信息(事务类别请假)
		@PostMapping("find_all_affca")
		@ResponseBody
		public List<Affaircategory> findallaff(){
			return operationservice.selectAll_affca();
		}
		//显示所有q信息(事务类别补班)
		@PostMapping("find_all_buban")
		@ResponseBody
			public List<Affaircategory> findallbuban(){
				return operationservice.selectAll_buban();
			}
		
		//显示所有q信息(事务类别外勤)
		@PostMapping("find_all_waiqin")
		@ResponseBody
			public List<Affaircategory> findallwaiqin(){
				return operationservice.selectAll_waiqin();
			}
		//显示所有q信息(事务类别加班)
		@PostMapping("find_all_jiaban")
		@ResponseBody
		public List<Affaircategory> findalljiaban(){
			return operationservice.selectAll_jiaban();
		}
		//显示所有q信息(事务类别调休)
		@PostMapping("find_all_tiaoxiu")
		@ResponseBody
			public List<Affaircategory> findalltiaoxiu(){
				return operationservice.selectAll_tiaoxiu();
			}
		
		//显示所有q信息(事务类别补卡)
		@PostMapping("find_all_buka")
		@ResponseBody
			public List<Affaircategory> findallbuka(){
				return operationservice.selectAll_buka();
			}
		
		//显示所有信息(员工清单查找)
		@RequestMapping("sheet_findall_staff")
		@ResponseBody
		public Map findallhostr(int page, int rows){
			long total = operationservice.attByPageCounts();
			List<StaffInformation> list =operationservice.selectAll_qindancz(page, rows);
			Map map = new HashMap<>();
			map.put("total", total);
			map.put("rows", list);
			return map;
		}
		
		//删除
		
		@PostMapping("to_delect_all_options")
		@ResponseBody
		public void Sales(Long conaffId){
			operationservice.Sales(conaffId);
		}
}
